'use strict';
	angular.module('inventory.groupCKFLMove', ['app.services'])

	.controller('groupCKFLMoveCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , f])//控制器结束
    function f($rootScope, $scope, BizData, $uibModalInstance, params, title) {

   		var Model = this;
   		
		var billType = "CKFL";
   		
   		var options = {};
		options.container = Model;
		options.concept = 'FileGroup';
		options.name = 'dataMaster';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
   		options.creater = '/inventory/groupCKFL/tree/create';
   		options.reader = '/inventory/groupCKFL/tree/query';
   		options.writer = '/inventory/groupCKFL/tree/save';
   		options.deleter = '/inventory/groupCKFL/tree/delete';
   		options.idColumnDefine = "fID";
   		options.idColumnName = "fID";
   		options.isTree = true;
   		options.parentRelation = 'fParent';
   		options.nodeKindRelation = 'nodeKind';
   		options.nodeLevelRelation = 'nodeLevel';
   		options.nodeSortRelation = "sortNo";
   		options.rootFilter = 'FileGroup.fParent is null';
   		options.pathRelation = 'storageFullID';
   		options.directDeleteMode = false;
   		options.limit = -1;
   		options.orderBy = 'sortNo ASC';

   		Model.dataMaster = new BizData(options);
   		//监视对象中的所有变动
//   	Model.dataMaster.deregRows = $scope.$watch('Model.dataMaster.rows',Model.dataMaster.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
   		//////////////////////////////////////////////

   		Model.dataMaster.filter = "FileGroup.billType='"+billType+"'";
		
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
            Model.title = title;  
            Model.params = params;
     	
       		Model.dataMaster.refreshData();

        });  
		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
        	var event = {};
        	if($scope.checkboxValue){
        		event.data = null;
        	}else{
   	    	var data = [];
    	    	var sourceRow = Model.dataMaster.rows[Model.dataMaster.currentIndex];
    	    	var row = {};
    			//循环行中的列，判断变化点是哪一个
    			for(var obj in sourceRow){
    				if(obj!='$$hashKey' && obj!='userdata'){
    					row[obj] = sourceRow[obj].value;
    				}
    			}
    	    	
    	    	data.push(row);
    	    	event.data = data;
        		
        	}
			$uibModalInstance.close(event);  
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////
	    



	    return Model;
	    
	}	
	
